package Game;

import java.util.ArrayList;

import Guns.Projectile;
import Levels.Level1;
import Levels.LevelLoader;
import Levels.Objects;
import LifeForms.Chaser;

public class Movement {
	public void movement(Dude character,Character images,boolean left,boolean right,boolean up,boolean down,int lastpressedxy,int lastpressedx,int lastpressedy,IndexCounter index){
		if(!down&&!up&&!right&&!left){			
			if(lastpressedx==1&&lastpressedxy==1){
				index.setCounter(images.StandingLeftArray.size(),0);
				character.setSprite(images.StandingLeft,1);
			}
			if(lastpressedy==1&&lastpressedxy==2){
				index.setCounter(images.StandingUpArray.size(),0);
				character.setSprite(images.StandingUp,1);
			}
			if(lastpressedx==2&&lastpressedxy==1){
				index.setCounter(images.StandingRightArray.size(),0);
				character.setSprite(images.StandingRight,1);
			}
			if(lastpressedy==2&&lastpressedxy==2){
				index.setCounter(images.StandingDownArray.size(),0);
				character.setSprite(images.StandingDown,1);
			}
		}
		if(!left&&!right){
			character.setHorMove(0);
		}
		if(!up&&!down){
			character.setVerMove(0);
		}
		if(up||down){
			if(up&&lastpressedy==1){
				character.setVerMove(-1);
				if(character.ID!=images.WalkingUp.getID()){
					index.setCounter(images.WalkingUpArray.size()-1,10);
					character.setSprite(images.WalkingUp,images.StandingUp.getID());
				}
			}
			if(down&&lastpressedy==2){
				character.setVerMove(1);
				if(character.ID!=images.WalkingDown.getID()){
					index.setCounter(images.WalkingDownArray.size()-1,10);
					character.setSprite(images.WalkingDown,images.StandingDown.getID());
				}
			}
		}
		if(left||right){
			if(right&&lastpressedx==2){
				character.setHorMove(1);
				if(character.ID!=images.WalkingRight.getID()){
					index.setCounter(images.WalkingRightArray.size()-1,10);
					character.setSprite(images.WalkingRight,images.StandingRight.getID());
				}
			}
			if(left&&lastpressedx==1){
				character.setHorMove(-1);
				if(character.ID!=images.WalkingLeft.getID()){
					index.setCounter(images.WalkingLeftArray.size()-1,10);
					character.setSprite(images.WalkingLeft,images.StandingLeft.getID());
				}
			}
		}
	}
	boolean spaceDelay=false;
	public void actions(Dude character,boolean spaceBar,ArrayList<Projectile> projectiles,Sprite bulletSprite,int x,int y){
		if(spaceBar&&!spaceDelay){
			spaceDelay=true;
			character.fire(projectiles,bulletSprite,x,y);
		}else if(!spaceBar&&spaceDelay){
			spaceDelay=false;
		}
	}
//	public void createbat(){
//		Chaser chaser=new Chaser(//sprite, 0,Mainth.level.getLevel().getX(),Mainth.level.getLevel().getY());
//		Mainth.level.getLevel().chasers.add(chaser);
//	}
}
